home *** CD-ROM | disk | FTP | other *** search
- /*******************
- PrintWD.c
- *******************/
-
- /**********************
- Include files
- ***********************/
- #include "String.h"
- #include "Messenger.h"
- #include "PrintTraps.h"
-
- /**********************
- Structures
- ***********************/
- typedef struct ditlheader {
- long HorP;
- Rect displayRect;
- char itemType;
- char dataLength;
- } ditlheader, *ditlheaderPtr, **ditlheaderHdl;
-
- /**********************
- Globals
- ***********************/
- THPrint ThePrintRec; /* Printing Stuff */
- TPPrPort ThePrintPort;
- TPrStatus PrintStatus;
- Rect PageRect;
- char forPrinting;
-
- /*************************************************/
- /*********** Printing Routines *******************/
- /*************************************************/
-
- /***************************/
- /* PrintControls() handles printing of standard buttons */
- PrintControls(theControl)
- ControlHandle theControl;
- { /* PrintControls() */
- ProcPtr controlRoutine;
- long dummy;
- int varCode, hilite;
-
- while (theControl != NULL) { /* control loop */
- varCode = GetCVariant(theControl);
- hilite = (**theControl).contrlHilite;
-
- HiliteControl(theControl, 0); /* LW does not support XOR */
- HLock((Handle) (**theControl).contrlDefProc);
- controlRoutine =(ProcPtr) *((**theControl).contrlDefProc);
- dummy = CallPascalL(varCode, theControl, 0, 0L, controlRoutine); /* Call CDEF to Draw */
- HUnlock((Handle) (**theControl).contrlDefProc);
- HiliteControl(theControl, hilite);
-
- theControl = (**theControl).nextControl;
- } /* control loop */
- } /* PrintControls() */
-
- /***************************/
- /* PrintList() handles printing of standard list */
- PrintList(theList)
- ListHandle theList;
- { /* PrintList() */
- Cell lCell;
- Rect lRect, dstRect;
- int lDataOffset, lDataLen;
- char dataPtr[255];
-
- if (theList == NULL) return;
- lCell.h = 0;
- lCell.v = 0;
- LDoDraw(TRUE, theList);
- do { /* loop through cells */
- LFind(&lDataOffset, &lDataLen, lCell, theList);
- LGetCell(&dataPtr, &lDataLen, lCell, theList);
- /*LFind(&lDataOffset, &lDataLen, lCell, theList);
- LSetCell(&dataPtr, lDataLen, lCell, pList);
- LDraw(lCell, pList);*/
- LRect(&lRect, lCell, theList);
- if (SectRect(&((**theList).rView), &lRect, &dstRect))
- if (EqualRect(&lRect, &dstRect)) { /* Draw it */
- TextBox(&dataPtr, lDataLen, &lRect, teJustLeft);
- }
- } while (LNextCell(TRUE, TRUE, &lCell, theList)); /* loop through cells */
- } /* PrintList() */
-
- /***************************/
- /* StrReplace() substitutes the first occurrence of t with r in s
- It returns TRUE if there was a substitution*/
- int StrReplace(s, t, r)
- char *s, *t, *r;
- { /* StrReplace() */
- char temp[256], *p;
-
- strcpy(temp, s);
- p = strstr(temp, t); /* find first occurrence */
- if (*p == '\0') return (0); /* no occurence */
-
- *p = '\0'; /* delete t */
- p = p + strlen(t); /* go to second half of string */
-
- strcpy(s, temp); /* get first part */
- strcat(s, r); /* put in replacement */
- strcat(s, p); /* put in second half */
-
- return (1);
- } /* StrReplace() */
-
- /***************************/
- /* PrintDialog() prints dialog substituting sX for ParamText */
- PrintDialog(d, s0, s1, s2, s3)
- DialogPeek d;
- Str255 s0, s1, s2, s3;
- { /* PrintDialog() */
- ditlheader *dh;
- Ptr p;
- int itemCount, i, theItem, datalen;
- int ResID, theType;
- Handle hItem;
- char text[256];
- Rect tempRect, box;
-
- p = (Ptr) *(*d).items;
- itemCount = *((int *) p); /* get number of dialog items */
-
- p = p + 2;
- for (i=0; i<= itemCount; i++) { /* Item Loop */
- dh = (ditlheader *) p;
-
- /* get type */
- theItem = dh->itemType;
- if (theItem < 0)
- theItem = theItem * -1;
- if (theItem >= 128)
- theItem -= 128;
-
- /* get length of data */
- datalen = dh->dataLength;
- if ((datalen % 2) != 0)
- datalen += 1;
-
- switch (theItem) { /* ItemType Switch */
- case ctrlItem + btnCtrl: /* Standard Button */
- case ctrlItem + chkCtrl: /* Checkbox */
- case ctrlItem + radCtrl: /* Radio Button */
- case ctrlItem + resCtrl: /* Resource Control */
- PrintControls((ControlHandle) dh->HorP); /* Draw controls */
- break;
-
- case editText:
- case statText:
- GetDItem((DialogPtr) d, i + 1, &theType, &hItem, &box);
- GetIText(hItem, (Str255 *) text);
- PtoCstr(text);
-
- /* make substitution of ParamText */
- PtoCstr((char *) s0);
- PtoCstr((char *) s1);
- PtoCstr((char *) s2);
- PtoCstr((char *) s3);
- while(StrReplace(text, "^0", (char *) s0));
- while(StrReplace(text, "^1", (char *) s1));
- while(StrReplace(text, "^2", (char *) s2));
- while(StrReplace(text, "^3", (char *) s3));
- CtoPstr((char *) s0);
- CtoPstr((char *) s1);
- CtoPstr((char *) s2);
- CtoPstr((char *) s3);
-
- TextBox(text, strlen(text), &(dh->displayRect), teJustLeft); /* draw text */
- if (theItem == editText) { /* draw edit text box */
- tempRect = dh->displayRect;
- FrameRect(&tempRect);
- }
- break;
-
- case iconItem:
- PlotIcon(&(dh->displayRect), (Handle) dh->HorP); /* draw icon */
- break;
-
- case picItem:
- DrawPicture((PicHandle) dh->HorP, &(dh->displayRect)); /* draw picture */
- break;
-
- case userItem:
- CallPascal((WindowPtr) ThePrintPort, i+ 1, (ProcPtr) dh->HorP); /* draw user item */
- break;
-
- default:
- break;
- } /* ItemType Switch */
- p = p + sizeof(ditlheader) + datalen;
- } /* Item Loop */
- } /* PrintDialog() */
-
- /***************************/
- /* InitPrint() initializes print variables */
- InitPrint()
- {
- ThePrintRec = NUL;
- PrOpen();
- ThePrintRec = (THPrint) NewHandle(sizeof(TPrint));
- PrintDefault(ThePrintRec);
- PageRect = (*ThePrintRec)->prInfo.rPage;
- PrClose();
- forPrinting = FALSE;
- PrSetError(noErr);
- } /* end InitPrint() */
-
- /***************************/
- /* doPageSetUp() handles page setup dialog */
- doPageSetUp()
- {
- char confirmed;
- WindowPtr SavePort;
- OSErr theError;
-
- InitCursor();
- GetPort(&SavePort);
- PrOpen();
- confirmed = PrValidate(ThePrintRec);
- confirmed = PrStlDialog(ThePrintRec);
- PrClose();
- theError = PrError();
- SetPort(SavePort);
- if (confirmed) {
- PageRect = (*ThePrintRec)->prInfo.rPage;
- }
- } /* end doPageSetUp() */
-
- /***************************/
- /* PrintWindow() handles printing */
- PrintWindow(theWindow)
- WindowPtr theWindow;
- {
- char DoIt; /* flag to do printing */
- TPrStatus PrintStatus; /* print variables */
- TPPrPort myPrPort;
- WindowPtr savePort;
- int copies, i, j, firstPage, lastPage, oldiPlayer;
- char dummy;
- Rect tempRect, pictRect, nameRect, windowRect;
- OSErr theError;
- GrafPtr aPort;
- Point oldOrigin;
-
- GetPort(&savePort); /* initialize printing */
- InitCursor();
- PrOpen();
-
- if (PrError() == noErr){ /* do print dialog */
- DoIt = PrValidate(ThePrintRec);
- DoIt = PrJobDialog(ThePrintRec);
- dummy = (int) AnOSError(PrError(), "\pProblem with Print Dialog", "\p");
-
- if (DoIt && !dummy) { /* Print Document */
- tempRect = theWindow->portRect;
- /* SetCursor(*watch); */
- InsetRect(&tempRect, -4, -4);
- pictRect = tempRect; /* set print variables up */
- PositionRect(&pictRect, &PageRect, CENTER, THIRD);
-
- ThePrintPort = PrOpenDoc(ThePrintRec, NUL, NUL);
- theError = PrError();
- if (!AnOSError(theError, "\pProblem with Printer", "\p")) { /* good port */
- /* get copies and page range */
- copies = (*ThePrintRec)->prJob.iCopies;
- firstPage = (*ThePrintRec)->prJob.iFstPage;
- lastPage = (*ThePrintRec)->prJob.iLstPage;
-
- if ((*ThePrintRec)->prJob.bJDocLoop == bSpoolLoop) /* check for spooling */
- copies = 1;
-
- /* check bad page range */
- if (firstPage > lastPage) {
- InitCursor();
- dummy = Message(M_OK, noIcon, "\pBad page range", "\p", "\p", "\p");
- }
- else { /* good page range */
- for (i=0; i<copies; i++) { /* valid picture */
- PrOpenPage(ThePrintPort, NUL); /* print page */
- theError = PrError();
- if (!AnOSError(theError, "\pProblem with page", "\p")) {
- FrameRect(&pictRect);
- GetPort(&aPort);
- oldOrigin = topLeft(aPort->portRect);
- SetOrigin(oldOrigin.h - pictRect.left, oldOrigin.v - pictRect.top);
- forPrinting = TRUE;
-
- UpDate_MyWindow(theWindow);
- UpDate_AboutDialog(theWindow);
- UpDate_TestDialog(theWindow);
-
- forPrinting = FALSE;
- SetOrigin(oldOrigin.h, oldOrigin.v);
- }
- PrClosePage(ThePrintPort);
- } /* end valid picture */
- }
- } /* end else good port */
- PrCloseDoc(ThePrintPort);
- if (((*ThePrintRec)->prJob.bJDocLoop == bSpoolLoop) && (PrError() == noErr))
- PrPicFile(ThePrintRec, NUL, NUL, NUL, &PrintStatus);
- /* print spool file, if any */
-
- } /* end of print document */
- } /* no error on PrOpen() */
-
- PrClose();
- SetPort(savePort);
- InvalRect(&tempRect);
- InitCursor();
- } /* end doPrint() */